<template>
	<view class="content">
		<form @submit="submitMember">
			<view class="list">
				<view class="list-title">个人信息</view>
				<view class="list-item">姓名： <input name="person_name" placeholder="请输入姓名" /></view>
				<view class="list-item">身份证号：<input name="person_identity" placeholder="请输入身份证号" /></view>
			</view>

			<view class="list">
				<button style="width: 100%;" form-type="submit">提交注册</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				group_id: "",

				gp_id: "", // 团体成员ID
			}
		},
		onLoad() {
		},
		created() {
			this.group_id = this.$route.query.group_id;
		},
		methods: {
			submitMember: function(e) {
				console.log(e.detail.value);

				if (!e.detail.value.person_name) {
					uni.showToast({
						title: '姓名不能为空',
						icon: 'none'
					})
					return
				}
				if (!e.detail.value.person_identity) {
					uni.showToast({
						title: '身份证不能为空',
						icon: 'none'
					})
					return
				}

				if ( !this.group_id ) {
					uni.showToast({
						title: '出错了！',
						icon: 'none'
					})
					return
				}

				uniCloud.callFunction({
					name: "ha_reg_member",
					data: Object.assign(e.detail.value, {
						group_id: this.group_id,
					}),
					success: ({result}) => {
						// console.log(result);

						if ( result.status === 0 ) {
							this.gp_id = result.data.gp_id;
							uni.setStorageSync("gp_id",this.gp_id);

							uni.showToast({
								title: `${result.msg || "注册成功！"}`,
								duration: 1000
							});

							location.reload();
						} else {
							uni.showToast({
								icon: 'none',
								title: `${result.msg || "网络异常，请稍后重试！"}`,
								duration: 1000
							});
						}
					},
					fail() {
						uni.showToast({
							icon: 'none',
							title: '网络异常，请稍后重试！'
						});
					}
				});
			}
		}
	}
</script>

<style>
	page {
		background: #f0f0f0;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-bottom: 50upx;
	}

	.list-item input {
		background: #f0f0f0;
		border-radius: 10upx;
		padding-left: 20upx;
		padding-right: 20upx;
		width: 300upx;
		height: 60upx;
		color: #999999;
		font-size: 30upx;

	}

	.xiala {
		display: flex;
		background: #f0f0f0;
		padding: 10upx;
		border-radius: 10upx;
		color: #999999;
		font-size: 30upx;

	}

	.xiala image {
		display: flex;
		padding-top: 5upx;
		width: 30upx;
		height: 30upx;
		margin-left: 10upx;

	}
</style>
